<template>
  <div class="courseDetail">
    <div class="left">
      <boxCard :course-info="courseInfo" @openDetail="openDetail" />
    </div>
    <div class="right">
      <el-tabs type="border-card">
        <el-tab-pane label="课程介绍">
          <introduce :course-info="courseInfo" />
        </el-tab-pane>
        <el-tab-pane label="开课期数">
          <div ref="periods" class="periods" />
        </el-tab-pane>
        <el-tab-pane class="pie" label="用户评价">
          <div class="comment-content">
            <comment />
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <el-dialog title="老师简介" :visible.sync="dialogFormVisible">
      <div class="teacher-info" v-html="courseInfo.teacher.description" />
    </el-dialog>
    <div class="menu" @click="openDrawer"><i class="el-icon-menu" /></div>
    <el-drawer
      title="内容大纲"
      :visible.sync="drawer"
      class="outline-drawer"
    >
      <div class="outline" v-html="outline">111</div>
    </el-drawer>
  </div>
</template>

<script>
import boxCard from '@/components/BoxCard/index'
import { terminfoMap } from '@/utils/dictionary'
import introduce from './introduce'
import comment from './comment'

export default {
  components: {
    boxCard,
    introduce,
    comment
  },
  data() {
    return {
      terminfoMap, // 课程分期字典
      periodsOptions: {
        xAxis: {
          data: []
        },
        yAxis: {},
        tooltip: {},
        legend: {
          data: ['课程期数数量']
        },
        series: [{
          name: '课程期数数量',
          type: 'bar',
          data: []
        }]
      },
      dialogFormVisible: false,
      courseInfo: {
        teacher: {
          largeFaceUrl: require('@/assets/img/avator.png')
        }
      },
      terminfo: {},
      outline: '', // 内容大纲
      drawer: false
    }
  },
  created() {
    this.getCourseDetail()
  },
  mounted() {
    this.getTerminfoList()
  },
  methods: {
    // 获取课程详情
    async getCourseDetail() {
      const { courseId } = this.$route.query
      const res = await this.$api.getCourseDetail(courseId)
      if (res && res.code === 200) {
        this.courseInfo = res.data
      }
    },
    // 获取课程期数列表
    async getTerminfoList() {
      const { courseId } = this.$route.query
      const res = await this.$api.getTerminfoList(courseId)
      if (res && res.code === 200) {
        this.terminfo = res.data.terminfo
        this.terminfo.forEach((item, index) => {
          if (item.termId === this.courseInfo.termId) {
            this.outline = item.outLine
          }
          this.periodsOptions.xAxis.data.push(this.terminfoMap[index])
          this.periodsOptions.series[0].data.push(item.enrollCount)
        })
        this.initPeriodsOption()
      }
    },
    initPeriodsOption() {
      const periodsChart = this.$echarts.init(this.$refs.periods)
      periodsChart.setOption(this.periodsOptions)
      window.addEventListener('resize', () => {
        periodsChart.resize()
      })
    },
    openDetail(val) {
      this.dialogFormVisible = true
    },
    openDrawer() {
      this.drawer = true
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/styles/mixin.scss";

.courseDetail{
  display: flex;
  .left, .right{
    top: 50%;
    transform: translateY(-50%);
  }
  .left{
    position: absolute;
    flex-basis: 300px;
    width: 300px;
    padding: 0 10px;
  }
  .right{
    position: absolute;
    left: 310px;
    right: 40px;
  }
  .teacher-info{
    text-indent: 2em;
    line-height: 20px;
    text-align:justify;
    text-align-last:left;
  }
  .comment{
    width: 400px;
    height: 300px;
  }
  .outline-drawer{
    .outline{
      padding: 0 10px;
    }
  }

  .pie{
    height: 60vh;
  }
  .periods{
    @include boxCenter;
    width: 600px;
    height: 300px;
  }
  .menu{
    position: fixed;
    display: flex;
    justify-content: center;
    align-items: center;
    right: 0;
    top: 45%;
    width: 40px;
    height: 40px;
    background-color: #fff;
    @include borderShadow;
    .el-icon-menu{
      font-size: 20px;
      color: #1989fa;
    }
  }
}

::v-deep .el-drawer__body{
  overflow: auto;
  @include scrollBar;
}

::v-deep :focus{
  outline: 0;
}

::v-deep .el-drawer__header{
  margin-bottom: 15px;
}

::v-deep .el-dialog__body{
  padding: 6px 20px 15px;
}

::v-deep .el-dialog__header{
  padding: 10px 20px;
  border-bottom: 1px solid #d4d4d4;
}

::v-deep .el-dialog__headerbtn{
  top: 12px;
}

::v-deep .el-tabs__content{
  height: 80vh;
}
</style>
